﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
using Visa.Service;
using Visa.DB;

namespace Visa.Common.Membership
{
    public class TBDSRoleProvider : RoleProvider
    {
        private UserService userService;
        private RolesSer Roluser; 

        public TBDSRoleProvider()
        {
            userService = new UserService();
            Roluser = new RolesSer();
        }

        private string applicationName = null;
        public override string ApplicationName
        {
            get
            {
                if (applicationName == null)
                {
                    applicationName = "AdminVisaTinBatDongSan24h";
                }
                return applicationName;
            }
            set { applicationName = value; }
        }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            
        }

        public override void CreateRole(string roleName)
        {

            Role roles = new Role();
            roles.Name = roleName;
            roles.DateCreate = DateTime.Now;
            roles.Deleted = false;
            roles.Staus = true;
            Roluser.InsertRoles(roles);

            return;
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {

            var c = Roluser.GetRolerInRoleName(roleName);
            Roluser.DeleteRoles(c);
            return true;
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            return Enum.GetValues(typeof(Role)).Cast<string>().ToArray();
        }

        public override string[] GetRolesForUser(string username)
        {
            string[] user = Roluser.GetRolesForUser(username);
            if (user != null)
            {
                return user;
            }
            return new string[] { string.Empty };
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            return Roluser.IsUserInRole(username, roleName);
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}
